package com.gate.ws.spring.rocketmq.consumer;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import com.gate.ws.spring.cache.LocalChannelCache;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;


import static com.nami.basic.constants.DownTopicConst.CLOSE_CHANNEL_TOPIC;


@Slf4j
@Component
@RocketMQMessageListener(topic = CLOSE_CHANNEL_TOPIC, consumerGroup = "${rocketmq.consumer.closeConsumerGroup}", selectorExpression = "${nami.mqTags}", consumeMode = ConsumeMode.CONCURRENTLY)
public class DownCloseChannelConsumer implements RocketMQListener<String> {

    @Override
    public void onMessage(String msg) {
        try {
            TimeInterval timer = DateUtil.timer();
            LocalChannelCache.removeAll(msg);
            if (timer.interval() > 500) {
                log.warn("[close-channel] userId:{}, use:{}ms", msg, timer.interval());
            }
        } catch (Exception var3) {
            var3.printStackTrace();
            log.error("[close-channel] error:", var3.getMessage());
        }
    }


}
